function inspect() {
    if (document.getElementById("password").value !=
        document.getElementById("repassword").value) {
        document.getElementById("warning").innerHTML = "两次密码的输入不一致!";
        document.getElementById("warning").style.color = "red";
    } else {
        document.getElementById("warning").innerHTML = "密码一致";
        document.getElementById("warning").style.color = "green";
    }
}

layui.use("layer");

function editPassword() {
    let data = {
        username: sessionStorage.getItem("user-name"),
        oldPassword: $("#oldPassword").val(),
        password: $("#password").val()
    }
    let reg = /^(?=.*[a-zA-Z])(?=.*[0-9])[A-Za-z0-9]{6,18}$/;
    console.log(data);
    if ($("#warning").text() == "密码一致") {
        if (!reg.test(data.password)) {
            layer.msg("请输入正确的密码格式！");
            return;
        } else {
            let result = myAjax('/user/editPassword', 'post', data);
            if (result === 1) {
                layer.msg("已保存修改！");
                parent.layer.closeAll();
            } else {
                layer.msg("密码错误！")
            }
        }
    }
}